package com.naihe.anderson.sms.widgets;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.text.method.ScrollingMovementMethod;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.naihe.anderson.sms.R;

public class InfoAlertDialog extends Dialog {

	private Handler mHandler;
	
	TextView contentTv;
	Button checkbtnCancel;
	
	String content = "";
	String checkbtnCancelText = "";
	Message message;
	
	public InfoAlertDialog(Context context, Handler mHandler, String content, String checkbtnCancelText, Message message) {
		super(context, R.style.progressStyle);
		this.mHandler = mHandler;
		this.content = content;
		this.message = message;
		
		this.checkbtnCancelText = checkbtnCancelText;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.info_alert_layout);
		
		contentTv = (TextView) findViewById(R.id.content_tv);
		contentTv.setText(content);
		contentTv.setMovementMethod(ScrollingMovementMethod.getInstance());		
		
		checkbtnCancel = (Button) findViewById(R.id.checkbtn_cancel);
		if(!TextUtils.isEmpty(checkbtnCancelText)){
			checkbtnCancel.setText(checkbtnCancelText);
		}
		checkbtnCancel.setOnClickListener(new Button.OnClickListener(){  
			  
            public void onClick(View v) {  
            	if (mHandler != null && message != null){
                	mHandler.sendMessage(message);
                }
            	InfoAlertDialog.this.cancel();
            	InfoAlertDialog.this.dismiss();
            }  
        });
	}
	
	@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK){
			this.cancel();
			mHandler = null;
			this.dismiss();
		}
		return super.onKeyDown(keyCode, event);

	}

	@Override
	public void show() {
		super.show();
	}

}
